package fem2;

/**
 * abstract class for all model part (element, load)
 * 
 * @author hbui
 * 
 */
public class ModelPart extends Echoer implements Comparable<ModelPart> {

	private int id;
	private MeshPart mp;

	private int activationLevel = 0; // always activate
	private boolean isInactive = false;

	public ModelPart(MeshPart mp) {
		this.mp = mp;
	}

	/**
	 * Returns the mesh part of the model part.
	 * 
	 * @return the mesh part
	 */
	public MeshPart getMeshPart() {
		return this.mp;
	}

	/**
	 * get id of this model part
	 * 
	 * @return model part's id
	 */
	public int getId() {
		return id;
	}

	/**
	 * set the id for this model part
	 * 
	 * @param id
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * get the activation level of this model part
	 * 
	 * @return the activationLevel
	 */
	public int getActivationLevel() {
		return activationLevel;
	}

	/**
	 * set the activation level
	 * 
	 * @param activationLevel
	 */
	public void setActivationLevel(int activationLevel) {
		this.activationLevel = activationLevel;
	}

	/**
	 * return false if this model part is active, true if not
	 * 
	 * @return
	 */
	public boolean isInactive() {
		return isInactive;
	}

	/**
	 * reactivate the model part
	 */
	public void reactivate() {
		this.isInactive = false;
	}

	/**
	 * deactivate the model part
	 */
	public void deactivate() {
		this.isInactive = true;
	}

	@Override
	public int compareTo(ModelPart o) {
		if (this == o) {
			return 0;
		}
		if (this instanceof Element && !(o instanceof Element)) {
			throw new Error("cannot compare two model part of different type");
		}
		if (this instanceof Load && !(o instanceof Load)) {
			throw new Error("cannot compare two model part of different type");
		}
		if (getId() > o.getId()) {
			return 1;
		} else if (getId() < o.getId()) {
			return -1;
		} else {
			throw new Error(
					"duplicated model part. Each model part of the same type must keep an unique id");
		}
	}

}
